import user.facory.AdminFactory;
import user.facory.IUserFactory;
import user.facory.NormalFactory;
import user.*;

import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 九转苍翎
 * Date: 2025/7/18
 * Time: 01:49
 */
public class LibrarySystem {
    public static void main(String[] args) {
        IUserFactory adminFactory = new AdminFactory();
        User admin = adminFactory.createUser("九转苍翎", 1);
        ProxyUser  proxyUserAdmin = new ProxyUser(admin);
        IUserFactory normalFactory = new NormalFactory();
        User normal = normalFactory.createUser("逆天而行", 2);
        ProxyUser  proxyUserNormal = new ProxyUser(normal);
        LibrarySystem librarySystem = new LibrarySystem();
        ProxyUser currentUser = librarySystem.selectProxyRole(proxyUserAdmin, proxyUserNormal);
        while(true){
            int choice = currentUser.menu();
            //此时无需关系是管理员还是普通用户,代理类会做权限判断
            currentUser.handleOperation(choice);
        }
    }
    public ProxyUser selectProxyRole(ProxyUser proxyUserAdmin,
                                     ProxyUser proxyUserNormal) {
        System.out.println("选择角色进行登录：");
        System.out.println("1.管理员(九转苍翎)\n2.普通用户(逆天而行)\n3.退出系统");
        ProxyUser currentUser = null;
        Scanner scanner = new Scanner(System.in);
        int choice = scanner.nextInt();
        switch (choice) {
        case 1:
            currentUser = proxyUserAdmin;
            break;
        case 2:
            currentUser = proxyUserNormal;
            break;
        case 3:
            System.out.println("退出系统");
            System.exit(0);
            break;
        default:
            break;
        }
        return currentUser;
    }
}